<style>
.delivery-status{font-size:14px;margin-left:15px;}
</style>

<form class="layui-form layui-form-pane" action="{:url('deliverySave', ['order_id' => $orderInfo['id']])}" method="post" id="editForm">

{foreach $deliveryList as $k => $v}
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
	<legend>{:$v['sub_client_ordernum']!=''?$v['sub_client_ordernum']:$orderInfo['client_ordernum']} <span class="delivery-status">{$deliveryStatusMap[$v['delivery_status']]}</span></legend>
</fieldset>
<div class="layui-form">
	<table class="layui-table">
		<thead>
			<tr>
				<th>尺码</th>
				{foreach $sizeList as $sk => $sv}
				<th>{$sv['size_name']}</th>
				{/foreach}
				<th>合计</th>
			</tr>
		</thead>
		<tbody>
			{if !empty($v['delivery_detail'])}
			<tr>
				<td>打包数</td>
				{foreach $sizeList as $sk => $sv}
				<td>{if isset($v['delivery_detail'][$sv['size_name']])}{$v['delivery_detail'][$sv['size_name']]}{/if}</td>
				{/foreach}
				<td>{$v['delivery_count']}</td>
			</tr>
			{/if}
			
			{if !empty($v['store_detail'])}
			<tr>
				<td>入仓数</td>
				{foreach $sizeList as $sk => $sv}
				<td>{if isset($v['store_detail'][$sv['size_name']])}{$v['store_detail'][$sv['size_name']]}{/if}</td>
				{/foreach}
				<td>{$v['store_count']}</td>
			</tr>
			{/if}
			
			{if $orderInfo['status']==2}
				<tr>
					<td>实际出货数</td>
					{foreach $sizeList as $sk => $sv}
					<td>{if isset($v['real_shipment_detail'][$sv['size_name']])}{$v['real_shipment_detail'][$sv['size_name']]}{/if}</td>
					{/foreach}
					<td>{:array_sum(array_values($v['real_shipment_detail']))}</td>
				</tr>
			{elseif $orderInfo['real_shipment_status']==1}
				<tr>
					<td>实际出货数</td>
					{foreach $sizeList as $sk => $sv}
					<td>
						<div class="layui-input-inline" style="width: 60px;">
							<input type="text" name="real_shipment[{$v['id']}][{$sv['size_name']}]" data-id="{$v['id']}" lay-verify="required|mimoint" value="{if isset($v['real_shipment_detail'][$sv['size_name']])}{$v['real_shipment_detail'][$sv['size_name']]}{else /}0{/if}" autocomplete="off" class="layui-input required item-input item-input-{$v['id']}">
					    </div>
				    </td>
					{/foreach}
					<td>
						<div class="layui-input-inline" style="width: 60px;">
							<input type="text" readonly value="{$v['real_shipment_count']}" autocomplete="off" class="layui-input total-{$v['id']}">
						</div>
					</td>
				</tr>	
			{else}
				<tr>
					<td>实际出货数</td>
					{foreach $sizeList as $sk => $sv}
					<td>
						<div class="layui-input-inline" style="width: 60px;">
							<input type="text" name="real_shipment[{$v['id']}][{$sv['size_name']}]" data-id="{$v['id']}" lay-verify="required|mimoint" value="{if isset($v['delivery_detail'][$sv['size_name']])}{$v['delivery_detail'][$sv['size_name']]}{else /}0{/if}" autocomplete="off" class="layui-input required item-input item-input-{$v['id']}">
					    </div>
				    </td>
					{/foreach}
					<td>
						<div class="layui-input-inline" style="width: 60px;">
							<input type="text" readonly value="{$v['delivery_count']}" autocomplete="off" class="layui-input total-{$v['id']}">
						</div>
					</td>
				</tr>				
			{/if}
			
		</tbody>
	</table>
</div>
{/foreach}

	{if $orderInfo['status']!=2}
	<div class="pop-bottom-bar">
        <button type="submit" class="layui-btn layui-btn-normal" lay-submit="" tabindex="1" lay-filter="formSubmit" hisi-data="{pop: true, refresh: false, jump: false}">提交{if $orderInfo['real_shipment_status']==1}修改{else}保存{/if}</button>
    </div>
    {/if}
</form>

{include file="system@block/layui" /}

<script type="text/javascript">
	layui.use([ 'jquery', 'layer', 'form', 'tool' ], function() {
		var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        
        // 实时计算总数
        $(document).on('change','.item-input',function(){
			var id = $(this).attr('data-id');
			console.log(id);
			var total=0;
			$(".item-input-"+id).each(function(){ 
				tmp = parseInt($(this).val());
				total = total + tmp;
			});
			$(".total-"+id).val(total);
		});
        
        var regFloat = /((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/; // 浮点数，小数点后两位
		var regInt = /^\d+$/; // 整数
        form.verify({
        	mimonumber: function(value, item){
        	    if (value=='') return '';
        	    if(! regFloat.test(value)){
        	    	return '只能填写数字';
        	    }
        	},
        	mimoint: function(value, item){
        	    if (value=='') return '';
        	    if(! regInt.test(value)){
        	    	return '只能填写数字';
        	    }
        	}
        });
	});
</script>